import React, { Component } from 'react';
import { observer, inject } from 'mobx-react';
import { Tools, Modal, Badge, Avatar } from 'weaver-mobile';
import RemindItemStore from '../../stores/remind/RemindItemStore';
const getLabel = Tools.getLabel;
@observer
export default class RemindItem extends Component {
    constructor(props) {
        super(props);
        this.state = {
            drop: false,
            store: new RemindItemStore(),
        }
    }
    componentWillMount() {
        const { store } = this.state;
        const { doNew } = store;
        doNew(this);
    }
    render() {
        const { drop, store } = this.state;
        const { role, isUnder, sender, saveRemindConf, sellChanceId, contactid, workPlanId, receivecof, senderName, createdate, senderNamespan,
            senderAvator, title, createtime, content, type, titlespan, senderAvatorspan, contactLogLayout, isSystem, timedSende, timedSendeState, receverSpan,
            sellchanceidspan, customer, customerSpan, contacter, contacterSpan, sellchancespan, receiver } = store;
        const { onHrmCardClick, onContactClick, onCustomerClick, onSellChanceCardClick, onContacterClick } = this.props;
        const params = { parentId: contactid, workPlanId: workPlanId, sellchanceid: sellChanceId, receiver: sender, type: 7 };
        //如果为接收人且未确认
        let showButton = <div></div>;
        let saveConf = false;
        if (isSystem == "1") {
            showButton = < div className='crm-remin-system'>{getLabel('84239', '系统提醒')}</ div>;
        } else if (timedSende == "true" && timedSendeState == "0") {
            showButton = < div className='crm-remin-system'>{getLabel('514769', '定时未发送')}</ div>;
        } else {
            if (role == "1" && receivecof == "0") {
                showButton = < div className='crm-remin-unconfie' onClick={(e) => { saveRemindConf(); e.stopPropagation() }}>{getLabel('514770', '点击确认')}</ div>;
                saveConf = true;
            } else if (role == "0" && receivecof == "0") {//当前人员为发送人且接收人未确认，显示未确认
                showButton = < div className='crm-remin-unconfie'>{getLabel('23062', '未确认')}</ div>;
            } else if (receivecof == "1") {
                showButton = <div className='crm-remin-confie'>{getLabel('18189', '已确认')}</div>;
            } else {
                showButton = <div></div>;
            }
        }

        return (
            <div className="crm-remind-item" style={{ position: "relative", overflow: "hidden" }}>
                <div className='crm-remind-item-content-row1'>
                    <div className='crm-remin-title' >
                        {type == 1 ? getLabel('514774', '联系记录评论提醒') : getLabel('514775', '新的提醒')}
                        {type == 1 && <svg style={{ right: "8", position: "absolute", margin: "2px 5px 0 0" }} t="1575940512465" className="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2038" width="20" height="20" onClick={() => { onContactClick && onContactClick({ workPlanId }) }}>
                            <path d="M852.8 74.4H171.2c-53.6 0-97.6 43.2-97.6 97.6v681.6c0 53.6 43.2 97.6 97.6 97.6h681.6c53.6 0 97.6-43.2 97.6-97.6V171.2c-0.8-53.6-44-96.8-97.6-96.8zM756 366.4H268.8V268.8h487.2v97.6z m0 194.4H268.8V463.2h487.2v97.6zM609.6 755.2H268.8V657.6h340.8v97.6z" fill="#409EFF" p-id="2039">
                            </path>
                        </svg>}
                    </div>
                    <div className='crm-remin-title-small' dangerouslySetInnerHTML={{ __html: content }} ></div>
                    {customer > 0 && <div className='crm-remind-realted-item' onClick={() => { onCustomerClick && onCustomerClick({ customerid: customer }); saveConf && saveRemindConf(); }}>{getLabel("783", "相关客户")}：<a>{customerSpan}</a></div>}
                    {sellChanceId > 0 && <div className='crm-remind-realted-item' onClick={() => { onSellChanceCardClick && onSellChanceCardClick({ sellChanceId }); saveConf && saveRemindConf(); }}>{getLabel(84372, "相关商机")}：<a>{sellchancespan}</a></div>}
                    {contacter > 0 && <div className='crm-remind-realted-item' onClick={() => { onContacterClick && onContacterClick({ contacterid: contacter }); saveConf && saveRemindConf(); }}>{getLabel(84373, "相关联系人")}：<a>{contacterSpan}</a></div>}
                    <div style={{ fontSize: "12px", display: "flex", color: "#aaa", margin: "5px 0px", position: "relative", overflow: "hidden", height: "20px" }}>
                        <div ><span onClick={() => { window.openLink.openHrm(sender); }}>{senderNamespan}</span>-><span onClick={() => { window.openLink.openHrm(receiver); }}>{receverSpan}</span></div>
                        <div style={{ margin: " 0 10px" }}>{createdate}</div>
                        <div>{createtime}</div>
                        {showButton}
                    </div>
                </div>
            </div>
        )
    }
}